from rest_framework import serializers

# serializers.Serializer

# serializers.ModelSerializer
from rest_framework.serializers import ModelSerializer

from apps.users.models import User


# 用户模型类的序列化器

class UserModelSerializer(ModelSerializer):
    class Meta:
        model = User
        # fields = '__all__'
        fields = ['id', 'username', 'mobile', 'email', 'password']

    # 重写create
    def create(self, validated_data):
        print("创建用户 并且加密")
        # 保存用户  用create_user 对密码加密
        user = User.objects.create_user(**validated_data)
        return user
